﻿using System;
using System.Collections.Generic;
using System.Text;
using KeePassLib;
using KeePass.UI;
using System.Windows.Forms;
using System.Linq;
using KeePassLib.Events;

namespace KeePass.Forms
{
    public class UserControlEditWriteRights : UserControlEditRights
    {

        protected override bool CheckedStateToChangeToAfterUserListChanged
        { get { return false; } }

        public UserControlEditWriteRights(AlternativeUser alternativeUser, PwDatabase db, CustomTreeViewEx ctmMainForm)
        {
            Construct(alternativeUser, db, ctmMainForm);
        }

        protected override void AddEventHandler(PwGroup group)
        {
            group.ReadableUserRemoved += new  PwGroup.UserAddedRemovedHandler(ChangeCheckedStateUserListChanged);
        }

        protected override bool UsersContains(TreeNode t, AlternativeUser au)
        {
            return ((PwGroup)t.Tag).WritableUsersContains(altUser);
        }

        protected override void AddUserToList(TreeNode t, AlternativeUser au)
        {
            ((PwGroup)t.Tag).AddWritableUser(au);
        }

        protected override void RemoveUserFromList(TreeNode t, AlternativeUser au)
        {
            ((PwGroup)t.Tag).RemoveWritableUser(au);
        }

        protected override void CheckedStateChangedAction(PwGroup group)
        {
            group.RemoveWritableUser(altUser);
        }
    }
}
